<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/js/jquery.js"></script>
    <link rel="stylesheet" href="/css/element-ui@2.13.2.index.css">
    <script src="/js/vue.min.js"></script>
    <script src="/js/vue-resource.min.js"></script>
    <script src="/js/index.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/axios.min.js"></script>
    <!-- 字体图标css的引入 -->
    <link rel="stylesheet" href="/css/font_830376_qzecyukz0s.css">
    <link rel="stylesheet" href="/css/color-dark.css">
    <link rel="stylesheet" href="/css/icon.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/base.css">
    <title></title>
</head>

<body>
<div id="manage">
    <!-- 头部 -->
    <div class="wrapper">
        <!-- 头部 -->
        <div class="header">
            <!-- 折叠按钮 -->
            <div class="header-left">
                人脸库管理
            </div>

            <!-- <div class="logo">后台管理系统</div> -->
            <div class="header-right">
                <div class="header-user-con">
                    <!-- 全屏显示 -->
                    <div class="btn-fullscreen" @click="handleFullScreen">
                        <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
                            <i class="el-icon-rank"></i>
                        </el-tooltip>
                    </div>
                    <div class="user-avator">
                        <img src="/image/img.jpg" />
                    </div>
                    <!-- 用户名下拉菜单 -->
                    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                            <span class="el-dropdown-link">
                                {{username}}
                                <i class="el-icon-caret-bottom"></i>
                            </span>
                        <el-dropdown-menu slot="dropdown">
                            <a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
                                <el-dropdown-item>项目仓库</el-dropdown-item>
                            </a>
                            <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </div>
        </div>

        <!-- 侧边部分 -->
        <div data-v-68d67528="" class="sidebar">
            <ul data-v-68d67528="" role="menubar" class="sidebar-el-menu el-menu side-ul"
                style="background-color: rgb(50, 65, 87);">
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-home"></i><span data-v-68d67528="">首页</span></li>
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item  is-active"
                    style="padding-left: 20px; color: rgb(32, 160, 255); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-calendar"></i><span data-v-68d67528="">人脸库管理</span>
                </li>
<!--                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"-->
<!--                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i-->
<!--                        data-v-68d67528="" class="el-icon-lx-copy"></i><span data-v-68d67528="">人员管理</span></li>-->
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-global"></i><span data-v-68d67528="">特征查询</span></li>
            </ul>
        </div>

        <!-- 内容部分 -->
        <div class="content-box">
            <div class="content">
                <div>
                    <div class="crumbs">
                        <el-breadcrumb separator="/">
                            <el-breadcrumb-item>
                                <i class="el-icon-lx-calendar"></i> 人脸库管理
                            </el-breadcrumb-item>
                            <el-breadcrumb-item>{{title}}</el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                    <div class="container">
                        <div class="form-box">
                            <el-page-header @back="back"></el-page-header>
                            <el-form ref="form" :model="form"
                                     label-width="250px" enctype="multipart/form-data">
                                </el-form-item>
                                <el-form-item  label="用户ID">
                                    <el-input v-model="request.id" name="id" readonly></el-input>
                                </el-form-item>
                                <el-form-item  label="人脸库名称">
                                    <el-input v-model="request.set_name" name="set_name"></el-input>
                                </el-form-item>
                                <el-form-item label="底库特征模型版本号">
                                    <el-select v-model="request.model_version" name="model_version" placeholder="请选择">
                                        <el-option
                                                v-for="item in model_versionOptions"
                                                :key="item.value"
                                                :label="item.label"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="人员图片">
                                <div class="form-group">
                                    <div class="group-upload-add" style="width: 100px">
                                        重新上传文件
                                        <input ref="file" id="file" type="file" name="file" @change="fileOnchange(this)" accept="image/jpeg, image/png">
                                    </div>
                                    <img id="img" ref="img" style="width: 178px; height: 178px;">
                                </div>
                                </el-form-item>
                                <el-form-item label="是否校验输入的特征为同一个人">
                                    <el-switch v-model="form.validity_check" name="validity_check"></el-switch>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click="onSubmit">{{btnText}}</el-button>
                                    <el-button @click="cancel">取消</el-button>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script th:inline="javascript">
    var manage = new Vue({
        el: '#manage',
        data: {
            fullscreen: false,
            title: '人脸用户详情',
            readonly: true,
            btnText: '修改',
            dialogVisible: false,
            action: window.url + '/api/user/update',
            headers: {
                'Authorization': window.localStorage['token']
            },
            actionUrl: window.url + '/api/user/upload',
            request: {
                id: [[${id}]],
                set_name: [[${setName}]],
                model_version: [[${modelVersion}]],
            },
            form: {
                id: [[${id}]],
                set_name: [[${setName}]],
                model_version: [[${modelVersion}]],
                features: [{
                    feature: '',
                    url: ''
                }],
                update_center: {
                    center: '',
                    num: 0
                },
                file: {},
                validity_check: true
            },
            // 判断图片是否改变
            imageIsChange: false
        },
        watch: {

        },
        computed: {
            username() {
                let username = localStorage.getItem('ms_username');
                return username ? username : this.name;
            }
        },
        mounted() {

        },
        created() {
            // 获取详情数据
            axiosPostRequest('/api/user/info', this.request)
                .then(result => {
                    if (result.status == 200) {
                        const data = result.data;
                        this.form.features = data.features;
                        this.form.update_center = data.update_center;
                        // 展示图片
                        this.$refs.img.src = data.features[0].url;
                    } else {
                        this.$message.error(result.message);
                    }
                })
        },
        methods: {
            // 文件改变时
            fileOnchange(e) {
                let files = document.getElementById('file').files;
                let file = files[0];
                let reader = new FileReader();
                reader.onload = () => {
                    this.$refs.img.src = reader.result;
                }
                this.form.file = file;
                reader.readAsDataURL(file);
                this.imageIsChange = true;
            },

            back() {
                window.history.back(-1);
            },

            onSubmit() {
                var form = new FormData();
                form.append('features', this.form.features);
                form.append('set_name', this.form.set_name);
                form.append('model_version', this.form.model_version);
                form.append('id', this.form.id);
                form.append('validity_check', this.form.validity_check);
                form.append('update_center', this.form.update_center);
                // 如果图像文件改变了则上传文件 没有改变则不上传
                if (this.imageIsChange) {
                    form.append('file', this.form.file);
                }
                axiosPostFormDataRequest('/api/user/update', form)
                    .then(result => {
                        if (result.status == 200) {
                            this.$message.success('修改人脸用户成功');
                        } else {
                            this.$message.error(result.message);
                        }
                    })
            },
            cancel() {
                window.history.back(-1);
            },

            // 检查文件是否超出指定的大小
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg' || 'image/png';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },

            // 用户名下拉菜单选择事件
            handleCommand(command) {
                if (command == 'loginout') {
                    localStorage.removeItem('ms_username');
                    window.localStorage["token"] = '';
                    window.location.href = 'login';
                }
            },
            // 全屏事件
            handleFullScreen() {
                let element = document.documentElement;
                if (this.fullscreen) {
                    if (document.exitFullscreen) {
                        document.exitFullscreen();
                    } else if (document.webkitCancelFullScreen) {
                        document.webkitCancelFullScreen();
                    } else if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen();
                    } else if (document.msExitFullscreen) {
                        document.msExitFullscreen();
                    }
                } else {
                    if (element.requestFullscreen) {
                        element.requestFullscreen();
                    } else if (element.webkitRequestFullScreen) {
                        element.webkitRequestFullScreen();
                    } else if (element.mozRequestFullScreen) {
                        element.mozRequestFullScreen();
                    } else if (element.msRequestFullscreen) {
                        // IE11
                        element.msRequestFullscreen();
                    }
                }
                this.fullscreen = !this.fullscreen;
            },
        }
    })

</script>

</body>

</html>